<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>修改用户信息</title>
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css" media="all">
<link rel="stylesheet" href="__PUBLIC__/admin/css/admin.css">
</head>
<body class="layui-bg-gray">
	<div class="layui-fluid">
		<div class="layui-row layui-col-space10">
			<div class="layui-col-md12 layui-col-xs12">
				<div class="layui-card">
					<form class="layui-form" action="">
						<div class="layui-card-body">
							<div class="layui-form-item">
								<label class="layui-form-label">登录账号</label>
								<div class="layui-input-block">
									<input type="text" name="username" required
										value="{$user.username}" lay-verify="required"
										placeholder="请输入账号" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">用户昵称</label>
								<div class="layui-input-block">
									<input type="text" name="name" required lay-verify="required"
										value="{$user.name}" placeholder="请输入用户昵称" autocomplete="off"
										class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">用户角色</label>
								<div class="layui-input-inline">
									<select id="role_id" name="role_id" lay-filter="roles">
										<option value="0">请选择角色</option>
										<volist name="roles" id="val"> </volist>
									</select>
								</div>
								<div class="layui-form-mid layui-word-aux">
									<a id="preview" data-id="0" class="layui-hide"
										style="cursor: pointer;">查看角色权限</a>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">状态</label>
								<div class="layui-input-block">
									<input type="checkbox" name="status" value="0"
										{$user['status']==
										0? 'checked' : ''}
										lay-skin="switch"
										lay-text="启用|禁用">
								</div>
							</div>
						</div>
						<div class="layui-card-footer">
							<div class="layui-input-block" style="text-align: right">
								<button class="layui-btn" lay-submit lay-filter="formDemo">保存修改</button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
	<script src="__PUBLIC__/layui/layui.js"></script>
	<script src="__PUBLIC__/layui/layui-xtree.js"></script>
	<script type="text/javascript"
		src="__PUBLIC__/common/js/jquery-2.0.3.min.js"></script>
	<script type="text/javascript">
		$(function() {
			layui.use('form', function() {
				var form = layui.form;
				form.on('select(roles)', function(data) {
					var val = data.value;
					if (val == 0) {
						!$("#preview").hasClass('layui-hide') ? $("#preview")
								.addClass('layui-hide') : '';
					} else {
						$("#preview").hasClass('layui-hide') ? $("#preview")
								.removeClass('layui-hide') : '';
					}
				});
				form.on('submit(formDemo)', function(data) {
					var role_id = data.field.role_id;
					if (role_id == 0) {
						layer.msg('请选择角色');
						return false;
					}
					var index = layer.load(3);
					$.ajax({
						type : "POST",
						url : "{:U('Limits/addUser')}",
						data : {
							info : data.field
						},
						success : function(res) {
							layer.close(index);
							if (res.status == 1) {
								layui.data('cache', {
									key : 'status',
									value : true
								});
								layer.msg(res.info, {
									icon : 1
								});
							} else {
								layer.msg(res.info, {
									icon : 2
								});
							}
						},
						error : function() {
							layer.close(index);
							layer.msg('服务器连接失败');
						}
					})
					return false;
				});
			});
		});
	</script>
</body>
</html>